<template>
  <div class="goods-tabs">
    <nav>
      <a :class="{active: activeName=== 'GoodsDetail'}" href="javascript:;"
         @click="activeName = 'GoodsDetail'">商品详情</a>
      <a :class="{active: activeName=== 'GoodsComment'}" href="javascript:;"
         @click="activeName = 'GoodsComment'">商品评价<span> ({{ goods.commentCount }})</span> </a>
    </nav>

    <!-- 切换内容的地方 其实是两个组件 -->
    <keep-alive>
      <component :is="activeName">
        <div></div>
      </component>
    </keep-alive>


  </div>
</template>

<script>
import { inject, provide, ref } from 'vue'
import GoodsComment from '@/components/goods/GoodsComment'
import GoodsDetail from '@/components/goods/GoodsDetail'

export default {
  name: 'GoodsTabs',
  components: {
    GoodsDetail,
    GoodsComment
  },
  setup() {
    // activeName的值为 GoodsDetail GoodsComment
    const activeName = ref('GoodsDetail')

    const goods = inject('goods')
    return {
      activeName,
      goods,
    }
  }
}
</script>

<style lang="less" scoped>
.goods-tabs {
  min-height: 600px;
  background: #fff;

  nav {
    display: flex;
    height: 70px;
    line-height: 70px;
    //text-align: center;
    border-bottom: 1px solid #f5f5f5;;

    a {
      position: relative;
      padding: 0 40px;
      font-size: 18px;

      &:first-child {
        border-right: 1px solid #f5f5f5;;
      }

      &:last-child {
        span {
          font-size: 16px;
          color: @priceColor;
        }
      }

      // 使用伪元素的方式去绘制active的下横线, 而不是简单的使用 border-bottom 来绘制
      &.active {
        &::before {
          content: '';
          position: absolute;
          bottom: -1px;
          left: 40px;
          width: 72px;
          height: 2px;
          background-color: @xtxColor;
        }
      }
    }
  }
}
</style>
